import React from 'react'
import { connect } from 'dva'

export const HomePage = ({ count, add, init, list }) => {
    return (
        <div>
            <h3>
                {count}
            </h3>
            {
                list.map((item, index) => {
                    return <p key = { index }>
                        { item.image_src}
                    </p>
                })
            }
            <button onClick={add}>加</button>
            {/* <button onClick={init}>初始化</button> */}
        </div>
    )
}

const mapStateToProps = (state) => {
    const { home: { count, list } } = state
    return {
        count,
        list
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        add() {
            dispatch({ type: "home/ADD_COUNT" })
        },
        init() {
            dispatch({ type: "home/INIT" })
        }
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(HomePage)